A well system (e.g., an oil or gas well) can include a wellbore drilled for extracting hydrocarbons from a hydrocarbon reservoir in a subterranean formation. The wellbore can be drilled into or through the hydrocarbon reservoir to provide access to the targeted hydrocarbons. After the wellbore has been drilled, the wellbore is completed. Completing a wellbore can include running a casing into the wellbore to prevent the wellbore from closing on itself. Cement can be pumped into the space between the wall of the wellbore and the casing to seal the wellbore from extraneous fluid and fix the casing in the wellbore. Casing and cementing the wellbore, however, can also seal the wellbore from the hydrocarbon reservoir, inhibiting the extraction of the targeted hydrocarbons. It can be desirable to reestablish access to the hydrocarbon reservoir, typically by using a perforating gun.
A perforating gun can include an explosive device that can be positioned in a wellbore adjacent to a hydrocarbon reservoir. When detonated, the perforating gun can pierce portions of the lining (e.g., the casing and cement) of the wellbore, thereby making the hydrocarbon reservoir accessible. Detonating the perforating gun, however, can cause the perforating gun to structurally deform and become trapped in the wellbore. This can render the perforating gun or a wellbore section inoperable.